<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        /**
         * component_access_token和authorizer_access_token
         */
        Schema::create('wxtoken', function (Blueprint $table) {
            $table->id();
            $table->integer('type')->nullable(false)->default(0);
            $table->string('appid', 128)->nullable(false)->default('');
            $table->text('token')->nullable(false);
            $table->timestamp('expire_at')->nullable(false);
            $table->timestamp('create_at')->default(DB::raw('CURRENT_TIMESTAMP'));
            $table->timestamp('update_at')->default(DB::raw('CURRENT_TIMESTAMP'))->useCurrentOnUpdate();
            $table->unique('appid');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('wxtoken');
    }
};
